#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
        int n, m, k;
        cin >> n >> m >> k;
        vector<int> ball(k + 1, 0);
        vector<int> hert(k + 1, 0);
        
        for(int i = 1; i <= k; i++){
                cin>>ball[i]>>hert[i];
        }

        vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
        for(int i = 1; i <= k; i++){
                for(int j = n; j >= ball[i]; j--){
                        for(int t = m; t >= hert[i]; t--){
                                dp[j][t] = max(dp[j][t], dp[j - ball[i]][t - hert[i]] + 1);
                        }
                }
        }

        cout<<dp[n][m]<<" ";

        int idx = m;
        while(idx > 0 && dp[n][m] == dp[n][idx]){
                idx--;
        }
        
        if(dp[n][m]){
                cout<<m - (idx + 1)<<endl;
        }else{
                cout<<m<<endl;
        }

        return 0;
}